<!DOCTYPE html>
<html>
<head>
    <title>Image Spider</title>
    <script src="/js/layout.js" type="text/javascript"></script>
    <script type="text/javascript">
        function ImageViewModel() {
            var self = this;
            self.Images = ko.observableArray([]);
        }

        $(function () {
            var imageVM = new ImageViewModel();
            ko.applyBindings(imageVM);

            $('#test').click(function () {
                var url = 'http://vgirl.weibo.com/5show/user.php?fid=12360';
                jsonrpc.invoke({
                    method: 'ajax',
                    params: { url: url },
                    success: function (ret) {
                        var urlInfo = parseURL(url);
                        $(ret.result.body).find('img').each(function () {
                            var src = $(this).attr('src');
                            if (src.indexOf('/') == 0) {
                                src = urlInfo.root + src.substring(1);
                            }
                            jsonrpc.invoke({
                                method: 'ajax',
                                params: {
                                    url: src,
                                    ext: { name: 'save', filename: 'e:/a/' + parseURL(src).file, minsize: 30000 }
                                },
                                success: function (data) {
                                    console.log(data);
                                }
                            });
                            //imageVM.Images.push(src);
                            //console.log(parseURL(src));
                        });
                    }
                });
            });
        });
    </script>
</head>
<body>
    <input id="test" type="button" value="Test" />
    <div data-bind="foreach:Images">
        <img alt="" data-bind="attr:{src:$data}" />
    </div>
</body>
</html>
